<?php

namespace app\common\validate\Business;

use think\Validate;

class Coupon extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'endtime'=>'afterNow',
        'rate'=>'between:0,1',
        'status'=>'in:0,1'
    ];
    /**
     * 提示消息
     */
    protected $message = [
        'endtime.afterNow'=>'结束时间必须要在现在之后',
        'rate.between'=>'折扣需为一个0到1的数',
        'status.in'=>'状态不正确'
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => [],
        'edit' => [],
    ];
    protected function afterNow($value, $rule, $data = [])
    {
        return $value >= time();
    }
}
